Scripts Overview

PreviousUpNext

Beyond Compare provides a script processing feature which allows you to automate routine tasks.  A script is a simple text file containing a list of commands which can control the program and automatically perform file operations or produce reports.

Scripts run without displaying the usual Folder Compare window, but might require input for certain confirmations.  To execute a script, specify it on the command line with a leading '@' symbol, as in:

BCompare.exe @C:\Scripts\MyScript.txt

At its most basic, a script is a simple series of commands.  The shortest meaningful script would be something like:

load "C:\Windows\Temp"
select all
delete all

which deletes all files and folders in the Windows "Temp" folder.

Scripts essentially manipulate an invisible folder comparison: file operations require selections, the "display" can be limited with filters, and folders can be "expanded" to recurse into them.  Any folder name argument can be a folder on your system, on the network or an FTP site, or the name of a folder-like archive such as .ZIP, .CAB, or Beyond Compare Snapshot file.

Scripts are processed line by line, with a single command per line.  Scripts are not case sensitive, and blank lines and comments (anything after a '#') are ignored.  Arguments are separated by spaces.  To include a space in an argument, surround the argument with quotes (").  To continue a long command on a second (or third) line, add an ampersand (&) at the end of every line but the last.

In addition to the standard commands, command line parameters and environmental variables can be inserted into the script at run time.  Command line variables are specified by a percent sign (%) and a single number from 1-9.  The script name and command line switches starting with / are not included in the 1-9 list.  The scripting command:

load "%1"

would load whatever session was given on the command line, as in "BCompare @script.txt MySession".

Environmental variables are inserted by enclosing the variable name in percent signs, and are case sensitive.  The following performs the same as the earlier script, except it gets the folder from the environment:

load "%TMP%"
select all
delete all

There are several dynamic variables that Beyond Compare can fill in at each line of the script.  The %date% variable fills in the current date in the format yyyy-mm-dd.  The %time% variable's format depends on your computer's regional settings.  The %fn_time% variable outputs the time as hh-mm-ss, which can be used for filenames.

Scripting Options

The command line switches that affect scripting are /silent, /closescript, and the various /readonly switches.  Normally, script processing adds an entry on the Task Bar and displays a Scripting Status Window detailing its progress and any errors.  The /silent switch bypasses the Task Bar entry and Scripting Status Window, allowing Beyond Compare to process the script invisibly.

To change the script processing options, select Options from the Tools menu.  Check the Beep when finished option to have Beyond Compare sound an audible beep when it completes script processing.  This beep can alert you to check and close the Scripting Status window.  Close when finished causes Beyond Compare to automatically close its Scripting Status window when it completes script processing.  When used in conjunction with Beep when finished, the beep simply tells you the process has completed.

There is also a place to designate a Shared scripts folder.  When you provide a script name argument on the command line with no path designation, and there is no file of that name in the current folder, Beyond Compare will look in the Shared scripts folder for that script.